package com.hkd.product_service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hkd.common.api.ApiResponse;
import com.hkd.product_service.api.BrandInfoService;
import com.hkd.product_service.api.dto.BrandListQueryDTO;
import com.hkd.product_service.api.dto.InsertBrandDTO;
import com.hkd.product_service.api.vo.BrandListVO;
import com.hkd.product_service.mapper.BrandInfoMapper;
import com.hkd.product_service.api.entity.BrandInfo;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author HKD
 * @date 2022/9/17 21:17
 */
@RestController
public class BrandInfoServiceImpl extends ServiceImpl<BrandInfoMapper, BrandInfo> implements BrandInfoService {
    @Override
    public ApiResponse insertBrandDTO(String curUserId, InsertBrandDTO param) {
        BrandInfo brandInfo = BeanUtil.copyProperties(param, BrandInfo.class);
        brandInfo.setCreateId(curUserId);
        brandInfo.setUpdateId(curUserId);
        this.save(brandInfo);
        return ApiResponse.ok();
    }

    @Override
    public ApiResponse<Page<BrandListVO>> listBrand(BrandListQueryDTO param) {
        Page<BrandInfo> brandPage = this.page(new Page<>(param.getCurrent(), param.getSize()));
        Page<BrandListVO> brandPageVO = (Page<BrandListVO>) brandPage.convert(item ->
                BeanUtil.copyProperties(item, BrandListVO.class)
        );
        return ApiResponse.ok(brandPageVO);
    }
}
